package com.summer.user.center.controller;


import com.summer.user.center.model.MenuItem;
import com.summer.user.center.service.MenuService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by likun on 2017/1/13.
 *
 * 管理菜单和资源链接
 */
@RestController
@RequestMapping("/menu")
public class MenuController {

    private static Logger logger = LoggerFactory.getLogger(MenuController.class);

    @Autowired
    private MenuService menuService;

    @RequestMapping("/getTreeData")
    public MenuItem getTreeData(){
        //查询出所有的菜单目录
       return menuService.findMenuItem();
    }

    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @RequestMapping(value="/update")
    public boolean update(MenuItem menu){
        Assert.notNull(menu.getId(),"菜单id不能为null");
        return menuService.update(menu);
    }

    /**
     * 添加菜单
     * @param menu
     * @return
     */
    @RequestMapping("/create")
    public boolean create(MenuItem menu){
        return menuService.create(menu);
    }

    /**
     * 删除菜单
     * @param id
     * @return
     */
    @RequestMapping("/delete")
    public boolean delete(Long id){
        Assert.notNull(id,"菜单id不能为null");
        return menuService.delete(id);
    }

    /**
     * 查找某个用户用权限访问的菜单
     * @param userId
     * @return
     */
    @RequestMapping("/findMenuByUserId")
    public MenuItem findMenuByUserId(Long userId){
        Assert.notNull(userId,"用户id不能为空");
        return menuService.findUserMenuItem(userId);
    }

}
